import 'package:flutter/material.dart';
import 'package:flutter_getx/app/modules/msg_list/controllers/msglist_controller.dart';
import 'package:get/get.dart';

class AddFriendDialog extends GetView<MsgListController> {

  final TextEditingController ctl = new TextEditingController();


  Widget buildContent() {
    return Container(
      height: 150,
      child: Column(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: [
          Padding(
            padding: const EdgeInsets.all(17.0),
            child: TextField(
              decoration: InputDecoration(
                labelText: "账号: ",
                isCollapsed: true,
                contentPadding:
                EdgeInsets.symmetric(horizontal: 10, vertical: 6),
                border: OutlineInputBorder(),
              ),
              keyboardType: TextInputType.number,
              controller: ctl,
            ),
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            children: [
              Row(
                children: [
                  Text("加群:", style: TextStyle(fontSize: 13),),
                  Obx(()=>Switch(value: controller.isAddGroup.value, onChanged: (e) {
                      controller.isAddGroup.value = e;
                  })),
                ],
              ),
              ElevatedButton(onPressed: () {
                controller.add(int.parse(ctl.text));
                Get.back(result: true);
              }, child: Text("加好友")),
            ],
          )
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return AlertDialog(
      contentPadding: EdgeInsets.zero,
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
      title: Text("添加好友/群"),
      content: buildContent(),
      actions: <Widget>[
        TextButton(
          onPressed: () {
            Get.back(result: false);
          },
          child: Text(
            '关闭',
            style: TextStyle(
              color: Get.theme.primaryColor,
            ),
          ),
        ),
      ],
    );
  }
}
